﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameLayer;
using Microsoft.Xna.Framework;

namespace GameBase
{
    public class Button : VisibleGameEntity<Sprite>, IDisposable
    {
        public Sprite Current
        {
            get
            {
                return this.Items[this.Index];
            }
        }
        public override Vector2 Size
        {
            get
            {
                return Current.Size;
            }
            set
            {
                base.Size = value;
            }
        }
        public override int Index
        {
            get
            {
                return base.Index;
            }
            protected set
            {
                this.Items[value].Position = this.Position;
                base.Index = value;
                Current.Index = 0;
            }
        }
        public override Microsoft.Xna.Framework.Vector2 Position
        {
            get
            {
                return base.Position;
            }
            set
            {
                base.Position = value;
                if (this.Items.Count > 0)
                    this.Items[this.Index].Position = value;
            }
        }
        protected override void Paint(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, object extraData)
        {
            Current.Draw(gameTime, spriteBatch);
        }



        public void Dispose()
        {
            if (!IsDisposed && Items != null)
            {
                foreach (var sprite in Items)
                {
                    sprite.Dispose();
                }
                IsDisposed = true;
            }

        }

        public bool IsDisposed { get; set; }
    }
}
